# Mega
MACH=arduino:avr:mega:cpu=atmega2560
PORT=/dev/ttyACM0
BAUD=115200
CPU=atmega2560
PROTO=wiring

HARD=/usr/share/arduino/hardware
TOOLS=/usr/share/arduino/tools

SRC=momo.c
BASE=$(shell pwd)
BUILD=$(BASE)/.build
OBJ=.build/$(SRC).hex

all:
	rm -rf .build; mkdir .build 
	arduino-builder -hardware $(HARD) \
	-tools $(TOOLS) -fqbn $(MACH) \
	-build-path $(BUILD) -compile $(SRC)

upload:
	while [ \! -c /dev/ttyACM0 ]; do echo "Missing /dev/ttyACM0!"; sleep 1; done
	avrdude -V -F -C /etc/avrdude.conf -c $(PROTO) \
	-p $(CPU) -P $(PORT) -b $(BAUD) \
	-U flash:w:$(OBJ)

clean:
	rm -rf $(BUILD)
	mkdir $(BUILD)
